<?php
//自动生成,请根据需要修改
namespace app\service\controller;
use app\common\controller\Base;
use think\Config;
use think\db\Where;
use think\facade\Request;
use think\Db;
/**
* @title 客服窗口接口
* @description 客服窗口说明
* @group 客服
*/
class ServiceChat extends Base{

	/**
	* @title 插入记录
	* @description 插入客服窗口数据
	* @author 开发者（范浩婷）
	* @url /service/service_chat/add
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:merchant_id type:Int require:1 default:0 other: desc:商城id
	* @param name:last_service_account_id type:Int require:1 default:0 other: desc:最后的客服账号id
	* @param name:in_service type:TinyInt require:1 default:0 other: desc:服务中
	* @param name:service_info type:VarChar require:1 default:0 other: desc:简介
	* @param name:create_time type:Int require:1 default:0 other: desc:创建时间
	* @param name:is_delete type:TinyInt require:1 default:0 other: desc:已删除
	* @param name:status type:TinyInt require:1 default:0 other: desc:状态(1-正在使用中、0-禁用中)
	* @param name:service_title type:VarChar require:1 default:0 other: desc:窗口名称
	* @param name:chat_id type:Int require:1 default:0 other: desc:窗口id
	* @param name:is_close type:TinyInt require:1 default:0 other: desc:已关闭
	* @param name:close_time type:Int require:1 default:0 other: desc:关闭时间
	* @param name:last_dialog_id type:Int require:1 default:0 other: desc:最后一次对话
	* @param name:logo type:Varchar require:1 default:0 other: desc:头像
     * @param name:user_identity type:Varchar require:1 default:0 other: desc:用户身份(u-用户，p-代理)
	*
	* @return merchant_id:商城id
	* @return last_service_account_id:最后的客服账号id
	* @return in_service:服务中
	* @return service_info:简介
	* @return create_time:创建时间
	* @return is_delete:已删除
	* @return status:状态
	* @return service_title:窗口名称
	* @return chat_id:窗口id
	* @return is_close:已关闭
	* @return close_time:关闭时间
	* @return last_dialog_id:最后一次对话
	* @return logo:头像
     * @return user_identity:用户身份
	*
	*/
	public function add (){
		//模块 - 输入数据
		$input=input();
		//模块 - 验证器
		$service_chatValidate = new \app\service\validate\ServiceChat;
		$validate = $service_chatValidate->scene('except_id')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $service_chatValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 新增  ---
		//插入的数据
		$insert_data = [
			'merchant_id'=>$input['merchant_id'],
			'last_service_account_id'=>$input['last_service_account_id'],
			'in_service'=>$input['in_service'],
			'service_info'=>$input['service_info'],
			'create_time'=>$input['create_time'],
			'is_delete'=>$input['is_delete'],
			'status'=>$input['status'],
			'service_title'=>$input['service_title'],
			'chat_id'=>$input['chat_id'],
			'is_close'=>$input['is_close'],
			'close_time'=>$input['close_time'],
			'last_dialog_id'=>$input['last_dialog_id'],
            'logo'=>$input['logo'],
            'user_identity'=>$input['user_identity']
		];
		//添加数据
		$insert_res = Db::name('service_chat')->data($insert_data)->insert();
		if(!$insert_res){
			$msg['msg'] = '插入数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $insert_res;

		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取列表数据（paginate）
	* @description 获取客服窗口的列表数据（分页）
	* @author 开发者（范浩婷）
	* @url /service/service_chat/get_list
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:merchant_id type:Int require:1 default:0 other: desc:商城id
	* @param name:last_service_account_id type:Int require:1 default:0 other: desc:最后的客服账号id
	* @param name:in_service type:TinyInt require:1 default:0 other: desc:服务中
	* @param name:service_info type:VarChar require:1 default:0 other: desc:简介
	* @param name:create_time type:Int require:1 default:0 other: desc:创建时间
	* @param name:is_delete type:TinyInt require:1 default:0 other: desc:已删除
	* @param name:status type:TinyInt require:1 default:0 other: desc:状态(1-正在使用中、0-禁用中)
	* @param name:service_title type:VarChar require:1 default:0 other: desc:窗口名称
	* @param name:chat_id type:Int require:1 default:0 other: desc:窗口id
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:is_close type:TinyInt require:1 default:0 other: desc:已关闭
	* @param name:close_time type:Int require:1 default:0 other: desc:关闭时间
	* @param name:last_dialog_id type:Int require:1 default:0 other: desc:最后一次对话
	* @param name:logo type:Varchar require:1 default:0 other: desc:头像
     * @param name:user_identity type:Varchar require:1 default:0 other: desc:用户身份(u-用户，p-代理)
	* @param name:page type:Int require:0 default:0 other: desc:当前页
	* @param name:pagesize type:Int require:0 default:0 other: desc:每页数量
	*
	* @return merchant_id:商城id
	* @return last_service_account_id:最后的客服账号id
	* @return in_service:服务中
	* @return service_info:简介
	* @return create_time:创建时间
	* @return is_delete:已删除
	* @return status:状态
	* @return service_title:窗口名称
	* @return chat_id:窗口id
	* @return id:id
	* @return is_close:已关闭
	* @return close_time:关闭时间
	* @return last_dialog_id:最后一次对话
	* @return logo:头像
     * @return user_identity:用户身份
	*
	*/
	public function get_list (){
		//模块 - 输入数据
        $input=input();
        // ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['merchant_id','=',$input['merchant_id']],
			['last_service_account_id','=',$input['last_service_account_id']],
			['in_service','=',$input['in_service']],
			['service_info','like','%'.$input['service_info'].'%'],
			['create_time','=',$input['create_time']],
			['is_delete','=',$input['is_delete']],
        	['service_title','like','%'.$input['service_title'].'%'],
			['status','=',$input['status']],
			['chat_id','=',$input['chat_id']],
			['id','=',$input['id']],
			['is_close','=',$input['is_close']],
			['close_time','=',$input['close_time']],
			['last_dialog_id','=',$input['last_dialog_id']],
            ['logo','=',$input['logo']],
            ['user_identity','=',$input['user_identity']]
		];
		//去除为空的条件
		$paginate_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($paginate_map,$v);
		}

		//获取数据
		$select_res = Db::name('service_chat')->where($paginate_map)->paginate();




//		$select_res['title'] =$service_user[]

		// paginate 返回数据
		$msg['list'] = $select_res;
		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取列表数据（select）
	* @description 获取客服窗口的列表数据（无分页）
	* @author 开发者（范浩婷）
	* @url /service/service_chat/get_select
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:merchant_id type:Int require:1 default:0 other: desc:商城id
    * @param name:merchant_type type:VarChar require:1 default:0 other: desc:商城类型
     *
	* @param name:last_service_account_id type:Int require:0 default:0 other: desc:最后的客服账号id
	* @param name:in_service type:TinyInt require:1 default:0 other: desc:服务中
	* @param name:service_info type:VarChar require:1 default:0 other: desc:简介
	* @param name:create_time type:Int require:1 default:0 other: desc:创建时间
	* @param name:is_delete type:TinyInt require:1 default:0 other: desc:已删除
	* @param name:status type:TinyInt require:1 default:0 other: desc:状态(1-正在使用中、0-禁用中)
	* @param name:service_title type:VarChar require:1 default:0 other: desc:窗口名称
	* @param name:chat_id type:Int require:0 default:0 other: desc:窗口id
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:is_close type:TinyInt require:1 default:0 other: desc:已关闭
	* @param name:close_time type:Int require:1 default:0 other: desc:关闭时间
	* @param name:last_dialog_id type:Int require:0 default:0 other: desc:最后一次对话
     * @param name:logo type:Varchar require:0 default:0 other: desc:头像
     * @param name:user_identity type:Varchar require:1 default:0 other: desc:用户身份(u-用户，p-代理)
     *
     * @param name:accept_account_id type:Varchar require:1 default:0 other: desc:接收者id
     * @param name:accept_account_type type:Varchar require:1 default:0 other: desc:接收者类型

	*
	* @return merchant_id:商城id
    * @return merchant_type:商城类型
	* @return last_service_account_id:最后的客服账号id
	* @return in_service:服务中
	* @return service_info:简介
	* @return create_time:创建时间
	* @return is_delete:已删除
	* @return status:状态
	* @return service_title:窗口名称
	* @return chat_id:窗口id
	* @return id:id
	* @return is_close:已关闭
	* @return close_time:关闭时间
	* @return last_dialog_id:最后一次对话
	* @return logo:头像
	* @return user_identity:用户身份
     *
     * @return accept_account_id:accept_account_id
     * @return accept_account_type:accept_account_type
	*
	*/
	public function get_select (){
		//模块 - 输入数据
        $input = input();
//        halt($input);

        // ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['merchant_id','=',$input['merchant_id']],
            ['merchant_type','like','%'.$input['merchant_type'].'%'],
			['last_service_account_id','=',$input['last_service_account_id']],
			['in_service','=',$input['in_service']],
			['service_info','like','%'.$input['service_info'].'%'],
			['create_time','=',$input['create_time']],
			['is_delete','=',$input['is_delete']],
			['status','=',$input['status']],
			['service_title','like','%'.$input['service_title'].'%'],
			['chat_id','=',$input['chat_id']],
			['id','=',$input['id']],
			['is_close','=',$input['is_close']],
			['close_time','=',$input['close_time']],
			['last_dialog_id','=',$input['last_dialog_id']],
            ['logo','=',$input['logo']],
            ['user_identity','=',$input['user_identity']],
		];

		//未读消息数量查询条件
        $map = [
//            ['send_account_id','=',$input['send_account_id']],
//            ['send_account_type','=',$input['send_account_type']]
            ['accept_account_id','=',$input['accept_account_id']],
            ['accept_account_type','=',$input['accept_account_type']]

        ];

		//去除为空的条件
		$select_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($select_map,$v);

		}

//		//查询最后一个客服是否在线
//        $zb_mqtt = config('database.zb_mqtt');
//
//        $is_online = Db::connect($zb_mqtt)->name('mqtt_client_onilne')
//                    ->where('account_id',$select_map['last_service_account_id'])
//                    ->find();
//
//        if($is_online == 1) {
//
//
//
//        } elseif($is_online == 0) {
//
//            //获取数据
//            $select_res = Db::name('service_chat')->strict(false)->where($select_map)->select();
//
//        }


        //获取数据
        $select_res = Db::name('service_chat')->strict(false)->where($select_map)->select();


        $zb_mqtt = config('database.zb_mqtt');
        foreach ($select_res as $k=>$v) {

            //过滤系统消息
            $find_map = new Where();
            $find_map['msg_type'] = ['not in',['create_chat','in_service']];
            $find_map['chat_id'] = $select_res[$k]['chat_id'];

            //获取最新的一条消息
            $v['last_msg'] = Db::connect($zb_mqtt)->name('msg')
                            ->where($find_map)
                            ->order('create_time', 'desc')
                            ->find();

            if($input['in_service']==0){
                //获取待接入列表消息数量
                $v['to_access_num'] = Db::connect($zb_mqtt)->name('account_msg')->where($find_map)->where($map)->count();

            }elseif ($input['in_service']==1){

                //获取待回复列表未读消息数量
                $v['to_reply_num'] = Db::connect($zb_mqtt)
                                    ->name('account_msg')
                                    ->where($map)
                                    ->where($find_map)
                                    ->where('send_account_id','<>',$input['accept_account_id'])
                                    ->where('accept_account_id',$input['accept_account_id'])
                                    ->where('is_accepted', 0)
                                    ->count();

                $v['unread_list'] = Db::connect($zb_mqtt)
                                    ->name('account_msg')
                                    ->where($map)
                                    ->where($find_map)
                                    ->where('is_accepted', 0)
                                    ->select();
            }


            $find_select=[
//                'service_account_id'=>$input['accept_account_id'],
//                'service_account_type'=>$input['accept_account_type'],
//                'merchant_id'=>$v['merchant_id']
            ];
//            $select_lists= Db::name('service_account')
//               ->where($find_select)
//                ->where('chat_id',$v['chat_id'])
//                ->select();


            $select_res[$k]['last_msg'] = $v['last_msg'];
            $select_res[$k]['to_access_num']=$v['to_access_num'];
            $select_res[$k]['to_reply_num']=$v['to_reply_num'];
            $select_res[$k]['unread_list']=$v['unread_list'];

//            $select_lists[$k]['last_msg'] = $v['last_msg'];
//            $select_lists[$k]['to_access_num']=$v['to_access_num'];
//            $select_lists[$k]['to_reply_num']=$v['to_reply_num'];
//            $select_lists[$k]['unread_list']=$v['unread_list'];



//                    logs("sql",Db::name('service_account')->getLastSql());
        }

        // select 返回数据
        $msg['list'] = $select_res;
//        $msg['res']=$select_lists;

		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
    /**
     * @title 获取单个窗口未读数量（get_one_select）
     * @description 获取单个窗口未读数量（无分页）
     * @author 开发者（范浩婷）
     * @url /service/service_chat/get_one_select
     * @method *
     *
     * @param name:token require:1 default: desc:token
     *
     * @param name:chat_id type:Int require:0 default:1 other: desc:窗口id
     * @param name:accept_account_id type:Varchar require:0 default:1 other: desc:接收者id
     * @param name:accept_account_type type:Varchar require:0 default:1 other: desc:接收者类型
     * @param name:status type:TinyInt require:0 default:0 other: desc:状态(1-正在使用中、0-禁用中)
     * @param name:id type:Int require:1 default:0 other: desc:id
     * @param name:is_close type:TinyInt require:0 default:0 other: desc:已关闭
     * @param name:close_time type:Int require:0 default:0 other: desc:关闭时间
     * @param name:user_identity type:TinyInt require:0 default:0 other: desc:用户身份(0-用户，1-代理)
     * @param name:merchant_id type:Int require:0 default:0 other: desc:商城id
     * @param name:last_service_account_id type:Int require:0 default:0 other: desc:最后的客服账号id
     *

     *
     * @return merchant_id:商城id
     * @return last_service_account_id:最后的客服账号id
     * @return in_service:服务中
     * @return service_info:简介
     * @return create_time:创建时间
     * @return is_delete:已删除
     * @return status:状态
     * @return service_title:窗口名称
     * @return chat_id:窗口id
     * @return id:id
     * @return is_close:已关闭
     * @return close_time:关闭时间
     * @return last_dialog_id:最后一次对话
     * @return logo:图像
     * @return user_identity:用户身份
     *
     * @return accept_account_id:accept_account_id
     * @return accept_account_type:accept_account_type
     *
     */
    public function get_one_select (){
        //模块 - 输入数据
        $input = input();
//        halt($input);

        // ---	模块 - 查询  ---
        //查询条件
        $temp_map = [
            ['merchant_id','=',$input['merchant_id']],
            ['last_service_account_id','=',$input['last_service_account_id']],
            ['in_service','=',$input['in_service']],
            ['service_info','like','%'.$input['service_info'].'%'],
            ['create_time','=',$input['create_time']],
            ['is_delete','=',$input['is_delete']],
            ['status','=',$input['status']],
            ['service_title','like','%'.$input['service_title'].'%'],
            ['chat_id','=',$input['chat_id']],
            ['id','=',$input['id']],
            ['is_close','=',$input['is_close']],
            ['close_time','=',$input['close_time']],
            ['last_dialog_id','=',$input['last_dialog_id']],
            ['logo','=',$input['logo']],
        ];

        //未读消息数量查询条件
        $map = [
//            ['send_account_id','=',$input['send_account_id']],
//            ['send_account_type','=',$input['send_account_type']]
            ['accept_account_id','=',$input['accept_account_id']],
            ['accept_account_type','=',$input['accept_account_type']]

        ];

        //去除为空的条件
        $select_map = [];
        foreach ($temp_map as $k=>$v){
            if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
                continue;
            }
            array_push($select_map,$v);

        }
        //获取数据
        $service_chat = Db::name('service_chat')->where($select_map)->find();

        $zb_mqtt = config('database.zb_mqtt');

            //过滤系统消息
            $find_map =new Where();
            $find_map['msg_type'] = ['not in',['create_chat','in_service']];
            $find_map['chat_id'] = $input['chat_id'];

            //获取最新的一条消息
            $last_msg = Db::connect($zb_mqtt)->name('msg')
                ->where($find_map)
                ->order('create_time', "desc")
                ->find();
            if($input['in_service']==0){
                //获取待接入列表消息数量
                $to_access_num= Db::connect($zb_mqtt)->name('account_msg')->where($find_map)->count();
            }elseif ($input['in_service']==1){

                //获取待回复列表未读消息数量
                $to_reply_num = Db::connect($zb_mqtt)
                    ->name('account_msg')
                    ->where($map)
                    ->where($find_map)
                    ->where('is_accepted', 0)
                    ->count();
            }
        $service_chat['last_msg'] = $last_msg;
        $service_chat['to_access_num']=$to_access_num;
        $service_chat['to_reply_num']=$to_reply_num;

        // select 返回数据
        $msg['data'] = $service_chat;


        //接口输出json数据
        $msg['msg'] = '操作成功！';
        return $this->successJson($msg);
    }
	/**
	* @title 获取单条数据
	* @description 根据ID获取客服窗口的指定记录
	* @author 开发者（范浩婷）
	* @url /service/service_chat/info
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	*
	*
	* @return id:id
	*
	*/
	public function info (){
		//模块 - 输入数据
		$input['id'] = Request::param('id/d');

		// input结果返回
		$msg['data']['id'] = $input['id'];

		//模块 - 验证器
		$service_chatValidate = new \app\service\validate\ServiceChat;
		$validate = $service_chatValidate->scene('only_id')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $service_chatValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
		];
		//去除为空的条件
		$find_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($find_map,$v);
		}

		//获取数据
		$select_res = Db::name('service_chat')->where($find_map)->find();

		// find 返回数据
		$msg['data'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 更新记录
	* @description 根据ID更新客服窗口指定记录的数据
	* @author 开发者（范浩婷）
	* @url /service/service_chat/edit
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:merchant_id type:Int require:1 default:0 other: desc:商城id
	* @param name:last_service_account_id type:Int require:1 default:0 other: desc:最后的客服账号id
	* @param name:in_service type:TinyInt require:1 default:0 other: desc:服务中
	* @param name:service_info type:VarChar require:1 default:0 other: desc:简介
	* @param name:create_time type:Int require:1 default:0 other: desc:创建时间
	* @param name:is_delete type:TinyInt require:1 default:0 other: desc:已删除
	* @param name:status type:TinyInt require:1 default:0 other: desc:状态(1-正在使用中、0-禁用中)
	* @param name:service_title type:VarChar require:1 default:0 other: desc:窗口名称
	* @param name:chat_id type:Int require:1 default:0 other: desc:窗口id
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:is_close type:TinyInt require:1 default:0 other: desc:已关闭
	* @param name:close_time type:Int require:1 default:0 other: desc:关闭时间
	* @param name:last_dialog_id type:Int require:1 default:0 other: desc:最后一次对话
     * @param name:logo type:Varchar require:1 default:0 other: desc:头像
     * @param name:user_identity type:Varchar require:1 default:0 other: desc:用户身份(u-用户，p-代理)
     *
     *
	* @return merchant_id:商城id
	* @return last_service_account_id:最后的客服账号id
	* @return in_service:服务中
	* @return service_info:简介
	* @return create_time:创建时间
	* @return is_delete:已删除
	* @return status:状态
	* @return service_title:窗口名称
	* @return chat_id:窗口id
	* @return id:id
	* @return is_close:已关闭
	* @return close_time:关闭时间
	* @return last_dialog_id:最后一次对话
     * @return logo:头像
     * @return user_identity:用户身份
	*/
	public function edit (){
		//模块 - 输入数据
        $input=input();
		//模块 - 验证器
		$service_chatValidate = new \app\service\validate\ServiceChat;
		$validate = $service_chatValidate->scene('all_field')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $service_chatValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 修改  ---
		//更新的条件
		$update_date = [
		'id'=>$input['id'],
		];
		//更新的数据
		$update_map = [
			'merchant_id'=>$input['merchant_id'],
			'last_service_account_id'=>$input['last_service_account_id'],
			'in_service'=>$input['in_service'],
			'service_info'=>$input['service_info'],
			'create_time'=>$input['create_time'],
			'is_delete'=>$input['is_delete'],
			'status'=>$input['status'],
			'service_title'=>$input['service_title'],
			'chat_id'=>$input['chat_id'],
			'is_close'=>$input['is_close'],
			'close_time'=>$input['close_time'],
			'last_dialog_id'=>$input['last_dialog_id'],
            'logo'=>$input['logo'],
            'user_identity'=>$input['user_identity']
		];
		//获取数据
		$update_res = Db::name('service_chat')->where($update_date)->update($update_map);
		if(!$update_res){
			$msg['msg'] = '更新据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $update_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 按条件删除记录
	* @description 按条件删除客服窗口的数据
	* @author 开发者（范浩婷）
	* @url /service/service_chat/delete
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:merchant_id type:Int require:1 default:0 other: desc:商城id
	* @param name:last_service_account_id type:Int require:1 default:0 other: desc:最后的客服账号id
	* @param name:in_service type:TinyInt require:1 default:0 other: desc:服务中
	* @param name:service_info type:VarChar require:1 default:0 other: desc:简介
	* @param name:create_time type:Int require:1 default:0 other: desc:创建时间
	* @param name:is_delete type:TinyInt require:1 default:0 other: desc:已删除
	* @param name:status type:TinyInt require:1 default:0 other: desc:状态(1-正在使用中、0-禁用中)
	* @param name:service_title type:VarChar require:1 default:0 other: desc:窗口名称
	* @param name:chat_id type:Int require:1 default:0 other: desc:窗口id
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:is_close type:TinyInt require:1 default:0 other: desc:已关闭
	* @param name:close_time type:Int require:1 default:0 other: desc:关闭时间
	* @param name:last_dialog_id type:Int require:1 default:0 other: desc:最后一次对话
     * @param name:logo type:Varchar require:1 default:0 other: desc:头像
     * @param name:user_identity type:Varchar require:1 default:0 other: desc:用户身份(u-用户，p-代理)
     *
     *
	* @return merchant_id:商城id
	* @return last_service_account_id:最后的客服账号id
	* @return in_service:服务中
	* @return service_info:简介
	* @return create_time:创建时间
	* @return is_delete:已删除
	* @return status:状态
	* @return service_title:窗口名称
	* @return chat_id:窗口id
	* @return id:id
	* @return is_close:已关闭
	* @return close_time:关闭时间
	* @return last_dialog_id:最后一次对话
	* @return logo:头像
     * @return user_identity:用户身份
	*
	*/
	public function delete (){
		//模块 - 输入数据
        $input=input();
		// ---  模块 - 删除  ---
		//删除的条件
		$temp_map = [
			['merchant_id','=',$input['merchant_id']],
			['last_service_account_id','=',$input['last_service_account_id']],
			['in_service','=',$input['in_service']],
			['service_info','=',$input['service_info']],
			['create_time','=',$input['create_time']],
			['is_delete','=',$input['is_delete']],
			['status','=',$input['status']],
			['service_title','=',$input['service_title']],
			['chat_id','=',$input['chat_id']],
			['id','=',$input['id']],
			['is_close','=',$input['is_close']],
			['close_time','=',$input['close_time']],
			['last_dialog_id','=',$input['last_dialog_id']],
            ['logo','=',$input['logo']],
            ['user_identity','=',$input['user_identity']]
		];
		$delete_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2] == null || $v[2] == ''){
				continue;
			}
			array_push($delete_map,$v);
		}
		if(empty($delete_map)){
			$msg['msg'] = '删除条件不能为空';
			return $this->errorJson($msg);
		}

		//删除数据
		$delete_res = Db::name('service_chat')->where($delete_map)->delete();
		if(!$delete_res){
			$msg['msg'] = '删除数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $delete_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}

}
